<script>
export default {
  name: 'XTabelActionDialogButton'
}
</script>
<script setup>
// start
import { createPromiseDialog } from '@/utils/createPromiseDialog'
import { inject, getCurrentInstance } from 'vue'

const { type, target, refresh, title, icon } = defineProps([
  'type',
  'target',
  'refresh',
  'title',
  'icon'
])

const row = inject('row')
const store = inject('store')

const dialog = createPromiseDialog(target)

async function clickHandler() {
  try {
    await dialog({ title }, { type, row })
    refresh && store.refresh()
  } catch (error) {
    console.error(error)
  }
}
</script>

<template>
  <el-button
    type="primary"
    @click="clickHandler"
    :icon="icon"
  >
    <slot>按钮</slot>
  </el-button>
</template>

<style scoped lang="scss">
// start
</style>
